
import React, { Component } from 'react';
import DynTable from './../../components/dynTable';
import './index.css';

/**
 * 查询策略信息
 */
const URL_STG_INFO = "http://10.254.251.233/api/xsse/getStgInfo.json";
/**
 * 查询策略订单
 */
const URL_STG_ORDER = "http://10.254.251.233/api/xsse/getStgOrder.json";
/**
 * 查询策略成交
 */
const URL_STG_EXEC = "https://10.254.251.175/api/xsse/getStgExec.json";
/**
 * 查询策略持仓
 */
const URL_STG_POS = "https://10.254.251.175/api/xsse/getStgPos.json";
/**
 * 查询策略日志
 */
const URL_STG_LOG = "http://10.254.251.233/api/xsse/getStgLog.json";

//策略信息-测试data
const TEST_DATA_STG_INFO = "?ip=172.0.0.1&mac=1234:56&server_id=1&token=8d421f8bf02d9b4dfc48e69b18020614";
//策略订单-测试data
const TEST_DATA_STG_ORDER = "?ip=172.0.0.1&mac=1234:56&server_id=1&token=8d421f8bf02d9b4dfc48e69b18020614&stg_name=st-test2&start_date=20181128&query_count=200";
//策略日志-测试data
const TEST_DATA_STG_LOG = "?ip=172.0.0.1&mac=1234:56&server_id=1&token=8d421f8bf02d9b4dfc48e69b18020614&stg_name=md_engine&query_count=20&query_index=0";
//策略成交-测试data
const TEST_DATA_STG_EXEC = "?ip=172.0.0.1&mac=1234:56&server_id=1&token=8d421f8bf02d9b4dfc48e69b18020614&stg_name=xiepeng-test&start_date=20181128&end_date=20181203&query_index=0&query_count=200";
//策略持仓-测试data
const TEST_DATA_STG_POS = "?ip=172.0.0.1&mac=1234:56&server_id=1&token=8d421f8bf02d9b4dfc48e69b18020614&stg_name=xiepeng-test&start_date=20181128&end_date=20181203&query_index=0&query_count=200";

class StrategyInfo extends Component {
    constructor(props) {
        super(props);
    }

    componentWillMount() {
        if (!this.isLogin()) {
            this.props.history.push('/login', null);
        }
    }

    loginUser = () => {
        return cookie.load('current-user');
    };

    isLogin = () => {
        const user = this.loginUser();
        return typeof (user) === 'object';
    };

    render() {
        return (
            <div className="dyntable_div">
                <DynTable url={URL_STG_INFO} data={TEST_DATA_STG_INFO} tableTitle={() => '策略查询'} isNeedActionCol={true} />
                <DynTable url={URL_STG_ORDER} data={TEST_DATA_STG_ORDER} tableTitle={() => '订单查询'} />
                <DynTable url={URL_STG_EXEC} data={TEST_DATA_STG_EXEC} tableTitle={() => '成交查询'} />
                <DynTable url={URL_STG_POS} data={TEST_DATA_STG_POS} tableTitle={() => '持仓查询'} />
                <DynTable url={URL_STG_LOG} data={TEST_DATA_STG_LOG} tableTitle={()=>'日志查询'} />
            </div>
        );
    }
}

export default StrategyInfo;